﻿using Pay.DTO;
using Pay.IService;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Security;
using Pay.TO;
using System;

namespace Pay.Distribution.Controllers {

    [RoutePrefix("grade")]
    public class GradeController : GeneralController {
        private IGradeService _iGradeService;
        private IMerchantService _iMerchantService;
        public GradeController(IGradeService iGradeService, IMerchantService iMerchantService) {
            _iGradeService = iGradeService;
            _iMerchantService = iMerchantService;
        }

       #region 商户级别
            [HttpGet]
            public JsonResult Get(long id) {
                var result = _iGradeService.Get(id);
                return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
            }
            [HttpGet]
            public JsonResult Gets() {
               var merchant = _iMerchantService.Get(currentUser.user_id);
               string merchant_no = "";
               if (merchant != null)
                  merchant_no = merchant.merchant_no;
               else
                  return Json(ResultToJson.Json("O商商户请登陆", ""), JsonRequestBehavior.AllowGet);
                var Manages = _iGradeService.Gets(merchant_no);
                return Json(ResultToJson.Json(Manages), JsonRequestBehavior.AllowGet);
            }
           [HttpPut]
           [ValidateInput(false)]
           public JsonResult Put(grade_dto dto) {
            var merchant = _iMerchantService.Get(currentUser.user_id);
            if (merchant != null)
                dto.merchant_no = merchant.merchant_no;
            else
                return Json(ResultToJson.Json("O商商户请登陆", ""), JsonRequestBehavior.AllowGet);
            var result = _iGradeService.Update(dto);
              return Json(ResultToJson.Json(result > 0 ? "保存成功" : "没有修改任何内容", result), JsonRequestBehavior.AllowGet);
           }
            [HttpPost]
            [ValidateInput(false)]
            public JsonResult Post(grade_dto dto) {
            var merchant = _iMerchantService.Get(currentUser.user_id);
            if (merchant != null)
                dto.merchant_no = merchant.merchant_no;
            else
                return Json(ResultToJson.Json("O商商户请登陆", ""), JsonRequestBehavior.AllowGet);
            var result = _iGradeService.Add(dto);
            return Json(ResultToJson.Json(result > 0 ? "保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
            }
            [HttpDelete]
            public JsonResult Delete(long id) {
                var result = _iGradeService.Delete(id);
                return Json(ResultToJson.Json(result > 0 ? "删除成功" : "删除失败", result), JsonRequestBehavior.AllowGet);
            }
            #endregion
    }
}